<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$setting=$this->plugin_setting('page_setting');
set_html('title','我的二维码');
$fromuser=$_RQ['fromuser']?:$_SESSION['uid'];
if($_RQ['fromuser']){
	$this->model('member')->checklogin();
	exi('','','/index/');
}
if($_RQ['op']=='main'){
	if($setting['closed_qrcode']){
		exi('没有开启推广二维码','error','/agent.index/');
	}
	$poster=$this->plugin_setting('poster');
	if($poster['isopen']==1){
		exi('','','/build/');
	}
	$setting['tcommission']=$setting['tcommission']?$setting['tcommission']:'佣金';
	if($setting['become_child']==1){
		$setting['t1']='如果您的好友下单，';
	}else{
		$setting['t1']='如果您的好友下单并付款，';
	}
	$setting['torder']=$setting['torder']?$setting['torder']:'分销订单';
	$setting['tmydown']=$setting['tmydown']?$setting['tmydown']:'我的下线';
	$setting['twithdraw']=$setting['twithdraw']?$setting['twithdraw']:'提现';	
	$return['setting']=$setting;
	$url=custom_url('jy_jicai/agent.qrcode/main/fromuser='.$fromuser,true);
	$return['qrcode']=cfc('tools')->createqrcode($url,'250',true);
	$return['qrcode']=tomedia($return['qrcode']);
	if($_SESSION['wxapp_id']){
		$image='oss/'.$_SESSION['uniacid'].'/images/jy_jicai/wxappid'.$fromuser.'.jpg';
		$isadd=cfc('files')->source_check($image);
		if(!$isadd){
			$url='/jy_jicai/agent.qrcode/index?fromuser='.$_SESSION['uid'];
			$wxapp=pdo_get('core_account_wxapp',array('id'=>$_SESSION['wxapp_id'],'uniacid'=>$_SESSION['uniacid']));
			if($_SESSION['fromh5wxapp']){
				$url='jy_jicai/agent.qrcode//fromuser='.$fromuser;
				$url='/pages/index/index?url='.urlencode($url);
			}
			$res=model('core/wxapp')->appcode($url,$wxapp['appid'],$wxapp['appsecret'],200);
			$path='oss/'.$_SESSION['uniacid'].'/images/jy_jicai/';
			if(!file_exists(ROOT_AT.$path)){
				mkdir(ROOT_AT.$path,0700, true);
			}
			$filename=$path.'/wxappid'.$fromuser.'.jpg';
			cfc('files')->source_save($res,'nochoose','png','二维码',$filename,'',$url);
		}
		$return['qrcode']=$return['appcode']=$image;
	}
	$member=model('core/member')->detail($fromuser,array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	$return['sharedata']=array(
			'title'=>'快来加入我的团队吧',
			'desc'=>'加入我的团，第一时机了解活动，优惠多多，活动多多！',
			'link'=>custom_url('jy_jicai/agent.qrcode/main/fromuser='.$fromuser,true),
			'imgUrl'=>tomedia($member['avatar']),
	);
	exi($return);
}

?>